package com.iemp.config.consts;


import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

public class EntityConsts {

    /* POJO */
    public final static String ASSOCIATION = "association";
    public final static String CAROUSEL = "carousel";
    public final static String FILE = "file";
    public final static String NEWS = "news";
    public final static String NOTICE = "notice";
    public final static String POLICY = "policy";
    public final static String PROJECT = "project";
    public final static String STAR = "star";
    public final static String INTRO = "intro";

    /* SECURITY */
    public static final String ACCOUNT = "account";
    public static final String ROLE = "role";

    /* FILE_TRANSFER */
    public static final String FILE_TRANSFER = "transfer";

    private static Map<String, String> map = new HashMap<>();
    private static boolean unloaded = true;

    public static Map<String, String> map() throws IllegalAccessException {
        Class<?> clazz = EntityConsts.class;
        Field[] fields = clazz.getDeclaredFields();
        Map<String, String> ret = new HashMap<>();
        for (Field field : fields) {
            String fieldName = field.getName();
            if ("map".equals(fieldName) || "unloaded".equals(fieldName)) {
                continue;
            }
            Object o = field.get(null);
            ret.put(fieldName, (String) o);
        }
        return ret;
    }

    public static String map(String key) throws IllegalAccessException {
        if (unloaded) {
            map = map();
        }
        return map.get(key);
    }

}
